import sys;
import os;
import os.path;

from fnmatch import fnmatch;

WHITELIST = ["build.xml" \
, "build-barebone.xml" \
, "build-component.xml" \
, "build-evacuated-component-macros.xml" \
, "build-core.xml" \
, "build-device.xml" \
];

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print "Usage: rmbuildxml.py <directory>";
        sys.exit(1);
        
    sDirectory = os.path.dirname(sys.argv[1]);
    for (curdir, dirs, files) in os.walk(sDirectory):
        for filename in files:
            if filename.lower() in WHITELIST:
                continue;
            
            if fnmatch(filename, "build-*.xml"):
                sFileToRemove = os.path.join(curdir, filename);
                try:
                    os.remove(sFileToRemove);
                    print "{0} is removed.".format(filename);                    
                except:
                    print "{0} can not be removed.".format(filename);
                
